﻿using System;
using System.Collections.Generic;
using System.Linq;
using NutriLeaf.Phone.Core.Gender;
using NutriLeaf.Phone.Core.Weight;
using NutriLeaf.Phone.Core.Height;


namespace NutriLeaf.Phone.Core.BMR
{
    public class BMR
    {
        public static int CalculateBMR(Gender.Gender gender, decimal weight, Weight.WeightUnits weightUnits, decimal height, Height.HeightUnits heightUnits, int age)
        {
            if (weightUnits == NutriLeaf.Phone.Core.Weight.WeightUnits.Kilograms)
            {
                weight = NutriLeaf.Phone.Core.Weight.Converter.Convert(weight, WeightUnits.Kilograms, WeightUnits.Pounds);
            }
            if (heightUnits == NutriLeaf.Phone.Core.Height.HeightUnits.Centimeters)
            {
                height = NutriLeaf.Phone.Core.Height.Converter.Convert(height, HeightUnits.Centimeters, HeightUnits.Inches);
            }

            if (gender == Gender.Gender.Male)
            {
                return Convert.ToInt32(66 + ((decimal)6.23 * weight) + ((decimal)12.7 * height) - ((decimal)6.8 * age));
            }

            if (gender == Gender.Gender.Female)
            {
                return Convert.ToInt32(655 + ((decimal)9.6 * weight) + ((decimal)4.7 * height) - ((decimal)4.7 * age));
            }
            return 0;
        }

        public static int CalculateActivityCalories(int BMR, ActivityLevel.ActivityLevel activity)
        {
            return (int)(BMR * GetActivityIndex(activity));
        }

        public static decimal GetActivityIndex(ActivityLevel.ActivityLevel activity)
        {
            if (activity == ActivityLevel.ActivityLevel.ExtraActive)
            {
                return (decimal)1.9;
            }

            if (activity == ActivityLevel.ActivityLevel.VeryActive)
            {
                return (decimal)1.725;
            }

            if (activity == ActivityLevel.ActivityLevel.ModeratelyActive)
            {
                return (decimal)1.55;
            }

            if (activity == ActivityLevel.ActivityLevel.LightlyActive)
            {
                return (decimal)1.375;
            }

            if (activity == ActivityLevel.ActivityLevel.Sedantary)
            {
                return (decimal)1.2;
            }
            return 0;

        }
    }
}